package com.mr.flowbean.sort3;

import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

/*
 * 对总流量降序排序
 * 13470253144	180	180	360
 * 封装流量到Bean
 */

public class FlowBeanMapper extends Mapper<LongWritable, Text, FlowBean, Text>{

	FlowBean fb = new FlowBean();

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, FlowBean, Text>.Context context)
			throws IOException, InterruptedException {


		String[] words = value.toString().split("\t");

		// 封装流量到FlowBean
		fb.setUpFlow(Long.parseLong(words[words.length - 3]));
		fb.setDownFlow(Long.parseLong(words[words.length - 2]));
		fb.setSumFlow(Long.parseLong(words[words.length - 1]));

		// 写出key-value
		// key：FlowBean
		// value：手机号
		context.write(fb, new Text(words[0]));

	}


}
